import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: LJHomePage(),
    );
  }
}

class LJHomePage extends StatelessWidget {
  const LJHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Center(
          child: Text("商品列表"),
        ),
      ),
      body: LJHomeContent("你好 赖家健"),
    );
  }
}

class LJHomeContent extends StatefulWidget {
  // const LJHomeContent({Key key}) : super(key: key);
  final String message;
  LJHomeContent(this.message);
  @override
  _LJHomeContentState createState() => _LJHomeContentState();
}

//_只允许自己使用
class _LJHomeContentState extends State<LJHomeContent> {
  int _count = 0;
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          _getButtons(),
          Text("当前计数$_count",style: TextStyle(fontSize: 25)),
          Text("传过来的message ${ this.widget.message }")
        ],
      ),
    );
  }
  Widget _getButtons (){
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ElevatedButton(onPressed:(){
          setState(() {
            _count++;
          });
        }, child: Icon(Icons.add)),
        ElevatedButton(onPressed: (){
          setState(() {
            _count--;
          });
        }, child: Icon(Icons.remove))
      ],
    );
  }
}

